
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author Sai
 * Created by Sai on 2019-04-02.
 */
@WebFilter(filterName = "Filter1" )
    public class Filter1 implements Filter {


    @Override
    public void init(FilterConfig filterConfig) {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

        HttpServletResponse res= (HttpServletResponse)response;
        HttpServletRequest req= (HttpServletRequest)request;
        HttpSession session =req.getSession();
        String value=(String)session.getAttribute("usename");
        String value1=req.getParameter("token");

        String value2=(String)session.getAttribute("use");

        if(value2==null) {
            System.out.println("a");
            session.setAttribute("use", "sa");
        }
        else   System.out.println("b");

         if(value==null){

           if(value1==null){
               System.out.println("sdfsd8");
               res.sendRedirect("https://cas.dgut.edu.cn?appid=javaee&state=STATE");

           }
           else {
               System.out.println("denglu");
               chain.doFilter(request, response);
           }
        }
        else{
            System.out.println("tuichu");
           chain.doFilter(request, response);
        }

    }

    @Override
    public void destroy() {

    }

}